home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / turbovis / hsys12.zip / EXAMPLE.ZIP / EXAPLE.PAS < prev    next >
Pascal/Delphi Source File  |  1993-08-20  |  7KB  |  252 lines

  1. program exaple;
  2.  
  3. uses objects, drivers, views, menus, app, dialogs, helpfile, msgbox,
  4.  
  5.      example;
  6.  
  7. Type
  8. {  ******************************************************************  }
  9. {  ******************************************************************  }
  10. {  Dialog                                                              }
  11. {  ******************************************************************  }
  12. {  ******************************************************************  }
  13.  
  14.      pmyapp = ^tmyapp;
  15.      TMyApp = object(TApplication)
  16.        myhelpwin : phelpwindow;
  17.        constructor init;
  18.        procedure   InitStatusLine; virtual;
  19.        procedure   handleEvent( Var Event: TEvent ); virtual;
  20.        procedure   GetEvent(VAR Event : TEvent ); virtual;
  21.      end;
  22.  
  23. Const cmakey       = 100;
  24.       cmhindexcall = 101;
  25.  
  26. Var MyApp        : TMyApp;
  27.     overridehelp : word;
  28.  
  29.  
  30. {  ******************************************************************  }
  31. {  ******************************************************************  }
  32. {  Application  }
  33. {  ******************************************************************  }
  34. {  ******************************************************************  }
  35. constructor tmyapp.init;
  36. Var R  : TRect;
  37.     sc : word;
  38. begin
  39.   inherited init;
  40.  
  41.   GetExtent ( R );
  42.   R.B.Y := R.A.Y + 1;
  43.   MenuBar := pmenubar(New ( pMenuBar, Init ( R, NewMenu (
  44.     NewSubMenu ( '~A Menu~',hcmenu,
  45.     NewMenu (
  46.       NewItem ( 'A Menutitem ~1~',  '', kbNoKey,  cmakey,   hcmenu,
  47.       NewItem ( 'A Menutitem ~1~',  '', kbNoKey,  cmakey,   hcmenu,
  48.       NewItem ( 'A Menutitem ~1~',  '', kbNoKey,  cmakey,   hcmenu,
  49.       NewItem ( 'A Menutitem ~1~',  '', kbNoKey,  cmakey,   hcmenu,
  50.       NewItem ( 'A Menutitem ~1~',  '', kbNoKey,  cmakey,   hcmenu,
  51.      nil)))))),
  52.     nil)))));
  53.   Insert(Menubar);
  54. end;
  55.  
  56.  
  57. Procedure Tmyapp.InitStatusLine;
  58. Var R : TRect;
  59.     p : pstatusitem;
  60.     q : pstatusdef;
  61.  
  62.   procedure stndhelp;
  63.   begin
  64.     p:=NewStatusKey('~F1~ Help', kbF1, cmhelp,p);
  65.   end;
  66.  
  67. Begin
  68.   GetExtent ( R );
  69.   R.A.Y := R.B.Y - 1;
  70.   q:=nil;
  71.  
  72. {defaulthelp, zuerst: }
  73.   p:=nil;
  74.   p:=NewStatusKey('',                         kbF10,       cmMenu,p);
  75.   p:=NewStatusKey('',                         kbshiftf1,   cmhindexcall,p);
  76.   p:=NewStatusKey('',                         kbf1,        cmhelp,p);
  77.   p:=NewStatusKey('',                         kbctrlf5,    cmresize,p);
  78.   p:=NewStatusKey('',                         kbf5,        cmzoom,p);
  79.   p:=NewStatusKey('',                         kbf6,        cmnext,p);
  80.   p:=NewStatusKey('',                         kbshiftf6,   cmprev,p);
  81.   p:=NewStatusKey('~Alt+X~ Exit',             kbAltX,      cmQuit,p);
  82.   q:=NewStatusDef(0,$FFFF,p,q);
  83.  
  84.   StatusLine := New(PStatusLine, Init(R,q));
  85.   Insert(statusline);
  86.  
  87.   registerhelpfile;
  88. end;
  89.  
  90. procedure tmyapp.handleEvent;
  91. Const exdate = 9;
  92. Var tmp : pointer;
  93. begin
  94.   inherited HandleEvent(Event);
  95.  
  96.   if (event.what=evcommand) then begin
  97.     clearevent(event);
  98.   end;
  99. end;
  100.  
  101. procedure tmyapp.GetEvent;
  102. var   W         : PHelpWindow;
  103.       HFile     : PHelpFile;
  104.       HelpStrm  : PDosStream;
  105.       helpfound : PHelpWindow;
  106.       hlpctx    : word;
  107.  
  108.       modal     : boolean;
  109.  
  110.  
  111. Const nonmodal      : boolean = false;
  112.       helpopenerror : boolean = false;
  113.  
  114.   function isdialoghelp:boolean;
  115.   begin
  116.     isdialoghelp:=(hlpctx>hc0firstcounterend) or (hlpctx<1);
  117.   end;
  118.  
  119.   procedure openhelpstream;
  120.   begin
  121.     w:=nil;
  122. { you should use your helpfilename here... }
  123.     HelpStrm := New(PDosStream, Init('example.hlp',stOpenRead));
  124.     if (HelpStrm^.Status<>stOk) then begin
  125. { help not found or not opend }
  126.       MessageBox(^c'Unable to open help', nil, mfError+mfOkButton);
  127.       ClearEvent(Event);
  128.       helpopenerror:=true;
  129.       exit;
  130.     end;
  131.     HFile:=New(PHelpFile, Init(HelpStrm));
  132. { will be nil, if not REGISTERHELPFILE }
  133.     if (hfile<>nil) and (not hfile^.modified) then begin
  134.       W:=New(PHelpWindow,Init(HFile,HlpCtx,isdialoghelp));
  135.       disposestr(w^.title);
  136.       w^.title:=newstr('Demo Help');
  137.      end else begin
  138. { didn't look like a Turbo Vision help or not REGISTERHELPFILE }
  139.       MessageBox(^c'Not a valid helpfile!', nil, mfError+mfOkButton);
  140.       ClearEvent(Event);
  141.       helpopenerror:=true;
  142.       exit;
  143.     end;
  144.   end;
  145.  
  146.   procedure callhelp;
  147.   Var deskcalc : byte;
  148.  
  149.     procedure quickcalcdesktop(p : pview); far;
  150.     begin
  151.       inc(deskcalc);
  152.     end;
  153.  
  154.     procedure findhelpfile(P: PView); far;
  155.     begin
  156. { if helpwindow already on desktop: focus and switch to page }
  157.       if (p<>nil) and (p^.Valid(cmClose)) and (typeof(p^)=typeof(thelpwindow)) and
  158.          (phelpwindow(p)=myhelpwin) then begin
  159.         helpfound:=phelpwindow(p);
  160.  
  161.         phelpwindow(p)^.focus;
  162.         phelpwindow(p)^.phv^.SwitchToTopic(hlpctx);
  163.       end;
  164.     end;
  165.  
  166.     procedure gotomodalpage(P: PView); far;
  167.     begin
  168. { if helpwindow already modal on desktop: switch to page }
  169.       if (p<>nil) and {(p^.Valid(cmClose)) and}
  170.          (typeof(p^)=typeof(thelpwindow)) and
  171.          (phelpwindow(p)^.ismodal) then begin
  172.         phelpwindow(p)^.phv^.SwitchToTopic(hlpctx);
  173.       end;
  174.     end;
  175.  
  176.   begin
  177.     deskcalc:=0;
  178.     desktop^.foreach(@quickcalcdesktop);
  179. { desktop empty and no helpctx? }
  180.     if (deskcalc=1) and (hlpctx=0) then
  181.       hlpctx:=0{hcmenudesktop};
  182.  
  183.     if (not nonmodal) and (not isdialoghelp) and (not helpopenerror) then begin { ein Fenster ruft...}
  184. { non modal }
  185.       helpfound:=nil;
  186.       desktop^.foreach(@findhelpfile);
  187.  
  188.       if (helpfound=nil) or (helpfound<>myhelpwin) then begin
  189.         openhelpstream;
  190.         if (not helpopenerror) and (ValidView(W)<>nil) then begin
  191.           desktop^.insert(W);
  192.           ClearEvent(Event);
  193.           myhelpwin:=w;
  194.         end;
  195.        end else
  196.         ClearEvent(Event);
  197.      end else begin
  198. { modal }
  199.       if (not nonmodal) then begin
  200.         nonmodal:=true;
  201.  
  202.         openhelpstream;
  203.         if (not helpopenerror) and (ValidView(W)<>nil) then begin
  204.           execview(W);
  205.           dispose(w,done);
  206.         end;
  207.  
  208.         nonmodal:=false;
  209.         ClearEvent(Event);
  210.       end;
  211.     end;
  212.   end;
  213.  
  214.  
  215. begin
  216.   inherited GetEvent(Event);
  217.  
  218.   if (Event.What=evCommand) and (Event.Command = cmHelp) then begin
  219. { helpwindow open? }
  220.     if (desktop^.current<>nil) and (typeof(desktop^.current^)=typeof(thelpwindow))
  221. {  yes: help about help }
  222.       then hlpctx:=hcabout
  223.      else
  224. { no: check overridehelp }
  225.       if (overridehelp<>0)
  226.         then hlpctx:=overridehelp
  227.         else begin
  228. { ok, get help. see Notice 2 }
  229.           if (desktop^.current=nil) and (myapp.current<>menubar)
  230.             then hlpctx:=0
  231.             else hlpctx:=gethelpctx;
  232.       end;
  233.     callhelp;
  234.   end;
  235.  
  236. { open helpindex, if help not on desktop }
  237.   if ((Event.What=evkeydown) and (Event.keycode=kbshiftf1)) or
  238.      ((Event.What=evcommand) and (Event.command=cmhindexcall)) then begin
  239.     hlpctx:=hcindexpage;
  240.     callhelp;
  241.   end;
  242. end;
  243.  
  244.  
  245. begin
  246.   overridehelp:=0;
  247.  
  248.   myapp.init;
  249.   myapp.run;
  250.   myapp.done;
  251. end.
  252.